# coding:utf-8

import numpy as np
import cv2
from scipy import misc

# 控制精度打印
np.set_printoptions(precision=3)


def regular(x_train):
    meannv = np.mean(x_train)
    stdv = np.std(x_train)
    data = (x_train - meannv) / stdv
    print(np.mean(data), data.std())
    return data


def minmax(data):
    mina = np.min(data)
    maxa = np.max(data)
    return (data - mina) / (maxa - mina)


def standardize(X):
    """特征标准化处理
    Args:
        X: 样本集
    Returns:
        标准后的样本集
    """
    m, n= X.shape
    # 归一化每一个特征
    for j in range(n):
        features = X[:, j]
        meanVal = features.mean(axis=0)
        std = features.std(axis=0)
        if std != 0:
            X[:, j] = (features - meanVal) / std
        else:
            X[:, j] = 0
    print(X.std(),X.mean())
    return X


def normalize(X):
    """Min-Max normalization     sklearn.preprocess 的MaxMinScalar
    Args:
        X: 样本集
    Returns:
        归一化后的样本集
    """
    m, n= X.shape
    # 归一化每一个特征
    for j in range(n):
        features = X[:, j]
        minVal = features.min(axis=0)
        maxVal = features.max(axis=0)
        diff = maxVal - minVal
        if diff != 0:
            X[:, j] = (features - minVal) / diff
        else:
            X[:, j] = 0


def do_regular(img):
    img = cv2.imread(img)
    cv2.imshow('immimijmimi',img)
    print(img)

    img = regular(img)
    # img = standardize(img)
    # img = minmax(img)
    # img = normalize(img)
    # img = np.log10(img)
    # img = img / 10 ** np.ceil(np.log(np.abs(img).max()))
    print(img)
    cv2.imshow('sfs',img)
    cv2.waitKey(0)

if __name__ == "__main__":
    img = r"C:\Users\Administrator\Desktop\0.jpg"
    do_regular(img)